﻿using SqlSugar;
using System.Linq.Expressions;

namespace Hotel.Application
{
    public interface IBaseService<TEntity, TCreateUpdateDto, TListDto>
        where TEntity : class, new()
        where TCreateUpdateDto : class, new()
        where TListDto : class, new()
    {
        /// <summary>
        /// 单条删除
        /// </summary>
        /// <param name="key"></param>
        /// <returns></returns>
        Task<int> DeleteAsync(long key);
        /// <summary>
        /// 添加
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        Task<long> InsertAsync(TCreateUpdateDto dto);
        /// <summary>
        /// 批量删除
        /// </summary>
        /// <param name="keys"></param>
        /// <returns></returns>
        Task<int> ManyDeleteAsync(List<long> keys);
        /// <summary>
        /// 批量删除
        /// </summary>
        /// <param name="keys"></param>
        /// <returns></returns>
        Task<int> ManyDeleteAsync(List<TEntity> entities);
        /// <summary>
        /// 批量添加
        /// </summary>
        /// <param name="dtos"></param>
        /// <returns></returns>
        Task<List<long>> ManyInsertAsync(List<TCreateUpdateDto> dtos);
        /// <summary>
        /// 批量更新
        /// </summary>
        /// <param name="dtos"></param>
        /// <returns></returns>
        Task<int> ManyUpdateAsyc(List<TCreateUpdateDto> dtos);
        /// <summary>
        /// 查单条
        /// </summary>
        /// <param name="key"></param>
        /// <returns></returns>
        Task<TListDto> FindAsync(long key);
        /// <summary>
        /// 查全部
        /// </summary>
        /// <returns></returns>
        Task<ResultDto<List<TListDto>>> QueryAsync();
        /// <summary>
        /// 按条件查
        /// </summary>
        /// <param name="expression"></param>
        /// <returns></returns>
        Task<List<TListDto>> QueryAsync(Expression<Func<TEntity, bool>> expression);
        /// <summary>
        /// 同步分页
        /// </summary>
        /// <param name="PageSize"></param>
        /// <param name="PageIndex"></param>
        /// <returns></returns>
        ResultDto<List<TListDto>> ToPageList(int PageSize = 10, int PageIndex = 1);
        /// <summary>
        /// 异步条件分页d
        /// </summary>
        /// <param name="expressionable"></param>
        /// <param name="PageSize"></param>
        /// <param name="PageIndex"></param>
        /// <returns></returns>
        Task<ResultDto<List<TListDto>>> ToPageListAsync(Expressionable<TEntity> expressionable, int PageSize = 10, int PageIndex = 1);
        /// <summary>
        /// 带排序字段的分页
        /// </summary>
        /// <param name="sort"></param>
        /// <param name="expressionable"></param>
        /// <param name="PageSize"></param>
        /// <param name="PageIndex"></param>
        /// <returns></returns>
        Task<ResultDto<List<TListDto>>> ToPageListAsync(Expression<Func<TEntity, object>> sort, Expressionable<TEntity> expressionable, int PageSize = 10, int PageIndex = 1);
        /// <summary>
        /// 异步分页
        /// </summary>
        /// <param name="PageSize"></param>
        /// <param name="PageIndex"></param>
        /// <returns></returns>
        Task<ResultDto<List<TListDto>>> ToPageListAsync(int PageSize = 10, int PageIndex = 1);
        /// <summary>
        /// 同步条件分页
        /// </summary>
        /// <param name="expressionable"></param>
        /// <param name="PageSize"></param>
        /// <param name="PageIndex"></param>
        /// <returns></returns>
        ResultDto<List<TListDto>> ToPageList(Expressionable<TEntity> expressionable, int PageSize = 10, int PageIndex = 1);
        /// <summary>
        /// 单条更新
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        Task<int> UpdateAsyc(TCreateUpdateDto dto);
        /// <summary>
        /// 更新某些字段
        /// </summary>
        /// <param name="dto"></param>
        /// <param name="columns">要更新的字段</param>
        /// <returns></returns>
        Task<int> UpdateAsyc(TCreateUpdateDto dto, string columns);
    }
}